home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / FromTheMag / JW FLV MEDIA PLAYER 4.2 / mediaplayer.exe / player.swf / scripts / com / jeroenwijering / player / View.as < prev   
Text File  |  2008-11-04  |  11KB  |  357 lines

  1. package com.jeroenwijering.player
  2. {
  3.    import com.carlcalderon.arthropod.Debug;
  4.    import com.jeroenwijering.events.AbstractView;
  5.    import com.jeroenwijering.events.ControllerEvent;
  6.    import com.jeroenwijering.events.ModelEvent;
  7.    import com.jeroenwijering.events.ViewEvent;
  8.    import com.jeroenwijering.utils.Strings;
  9.    import flash.display.MovieClip;
  10.    import flash.events.Event;
  11.    import flash.external.ExternalInterface;
  12.    import flash.system.Capabilities;
  13.    import flash.system.Security;
  14.    import flash.ui.ContextMenu;
  15.    import flash.utils.setTimeout;
  16.    
  17.    public class View extends AbstractView
  18.    {
  19.        
  20.       
  21.       private var listeners:Array;
  22.       
  23.       private var loader:SPLoader;
  24.       
  25.       private var _skin:MovieClip;
  26.       
  27.       private var _config:Object;
  28.       
  29.       private var model:Model;
  30.       
  31.       private var controller:Controller;
  32.       
  33.       private var context:ContextMenu;
  34.       
  35.       public function View(param1:Object, param2:MovieClip, param3:Controller, param4:Model, param5:SPLoader)
  36.       {
  37.          super();
  38.          Security.allowDomain("*");
  39.          _config = param1;
  40.          _config["client"] = "FLASH " + Capabilities.version;
  41.          _skin = param2;
  42.          if(_config["resizing"])
  43.          {
  44.             _skin.stage.scaleMode = "noScale";
  45.             _skin.stage.align = "TL";
  46.             _skin.stage.addEventListener(Event.RESIZE,resizeHandler);
  47.          }
  48.          loader = param5;
  49.          controller = param3;
  50.          model = param4;
  51.          setListening();
  52.          if(ExternalInterface.available && _skin.loaderInfo.url.indexOf("http") == 0)
  53.          {
  54.             listeners = new Array();
  55.             setJavascript();
  56.             setTimeout(playerReady,50);
  57.          }
  58.          if(config["file"])
  59.          {
  60.             setTimeout(sendEvent,200,ViewEvent.LOAD,config);
  61.          }
  62.       }
  63.       
  64.       override public function get config() : Object
  65.       {
  66.          return _config;
  67.       }
  68.       
  69.       private function addJSViewListener(param1:String, param2:String) : Boolean
  70.       {
  71.          listeners.push({
  72.             "target":"VIEW",
  73.             "type":param1.toUpperCase(),
  74.             "callee":param2
  75.          });
  76.          return true;
  77.       }
  78.       
  79.       private function forward(param1:String, param2:String, param3:Object) : void
  80.       {
  81.          var _loc4_:* = null;
  82.          var _loc5_:* = null;
  83.          var _loc6_:* = null;
  84.          var _loc7_:Object = null;
  85.          _loc4_ = "";
  86.          for(_loc5_ in param3)
  87.          {
  88.             _loc4_ += _loc5_ + ":" + param3[_loc5_] + ",";
  89.          }
  90.          if(_loc4_.length > 0)
  91.          {
  92.             _loc4_ = "(" + _loc4_.substr(0,_loc4_.length - 1) + ")";
  93.          }
  94.          if(config["tracecall"] == "arthropod")
  95.          {
  96.             _loc7_ = {
  97.                "CONTROLLER":"0xFF6666",
  98.                "VIEW":"0x66FF66",
  99.                "MODEL":"0x6666FF"
  100.             };
  101.             Debug.log(param2 + " " + _loc4_,_loc7_[param1]);
  102.          }
  103.          else if(config["tracecall"])
  104.          {
  105.             ExternalInterface.call(config["tracecall"],param1 + ": " + param2 + " " + _loc4_);
  106.          }
  107.          else
  108.          {
  109.             trace(param1 + ": " + param2 + " " + _loc4_);
  110.          }
  111.          if(!param3)
  112.          {
  113.             param3 = new Object();
  114.          }
  115.          param3.id = ExternalInterface.objectID;
  116.          param3.client = config["client"];
  117.          param3.version = config["version"];
  118.          for(_loc6_ in listeners)
  119.          {
  120.             if(listeners[_loc6_]["target"] == param1 && listeners[_loc6_]["type"] == param2)
  121.             {
  122.                ExternalInterface.call(listeners[_loc6_]["callee"],param3);
  123.             }
  124.          }
  125.       }
  126.       
  127.       private function getPlaylist() : Array
  128.       {
  129.          return controller.playlist;
  130.       }
  131.       
  132.       private function addJSModelListener(param1:String, param2:String) : Boolean
  133.       {
  134.          listeners.push({
  135.             "target":"MODEL",
  136.             "type":param1.toUpperCase(),
  137.             "callee":param2
  138.          });
  139.          return true;
  140.       }
  141.       
  142.       private function getConfig() : Object
  143.       {
  144.          var _loc1_:Object = null;
  145.          var _loc2_:* = null;
  146.          _loc1_ = new Object();
  147.          for(_loc2_ in _config)
  148.          {
  149.             if(_loc2_.indexOf(".") == -1)
  150.             {
  151.                _loc1_[_loc2_] = _config[_loc2_];
  152.             }
  153.          }
  154.          return _loc1_;
  155.       }
  156.       
  157.       override public function get playlist() : Array
  158.       {
  159.          return controller.playlist;
  160.       }
  161.       
  162.       private function playerReady() : void
  163.       {
  164.          var dat:Object = null;
  165.          if(ExternalInterface.available)
  166.          {
  167.             dat = {
  168.                "id":config["id"],
  169.                "client":config["client"],
  170.                "version":config["version"]
  171.             };
  172.             try
  173.             {
  174.                ExternalInterface.call("playerReady",dat);
  175.             }
  176.             catch(err:Error)
  177.             {
  178.             }
  179.          }
  180.       }
  181.       
  182.       private function setListening() : void
  183.       {
  184.          if(config["tracecall"] == "arthropod")
  185.          {
  186.             Debug.clear();
  187.          }
  188.          addControllerListener(ControllerEvent.ERROR,setController);
  189.          addControllerListener(ControllerEvent.ITEM,setController);
  190.          addControllerListener(ControllerEvent.MUTE,setController);
  191.          addControllerListener(ControllerEvent.PLAY,setController);
  192.          addControllerListener(ControllerEvent.PLAYLIST,setController);
  193.          addControllerListener(ControllerEvent.QUALITY,setController);
  194.          addControllerListener(ControllerEvent.RESIZE,setController);
  195.          addControllerListener(ControllerEvent.SEEK,setController);
  196.          addControllerListener(ControllerEvent.STOP,setController);
  197.          addControllerListener(ControllerEvent.VOLUME,setController);
  198.          addModelListener(ModelEvent.BUFFER,setModel);
  199.          addModelListener(ModelEvent.ERROR,setModel);
  200.          addModelListener(ModelEvent.LOADED,setModel);
  201.          addModelListener(ModelEvent.META,setModel);
  202.          addModelListener(ModelEvent.STATE,setModel);
  203.          addModelListener(ModelEvent.TIME,setModel);
  204.          addViewListener(ViewEvent.FULLSCREEN,setView);
  205.          addViewListener(ViewEvent.ITEM,setView);
  206.          addViewListener(ViewEvent.LINK,setView);
  207.          addViewListener(ViewEvent.LOAD,setView);
  208.          addViewListener(ViewEvent.MUTE,setView);
  209.          addViewListener(ViewEvent.NEXT,setView);
  210.          addViewListener(ViewEvent.PLAY,setView);
  211.          addViewListener(ViewEvent.PREV,setView);
  212.          addViewListener(ViewEvent.QUALITY,setView);
  213.          addViewListener(ViewEvent.REDRAW,setView);
  214.          addViewListener(ViewEvent.SEEK,setView);
  215.          addViewListener(ViewEvent.STOP,setView);
  216.          addViewListener(ViewEvent.TRACE,setView);
  217.          addViewListener(ViewEvent.VOLUME,setView);
  218.       }
  219.       
  220.       private function setView(param1:ViewEvent) : void
  221.       {
  222.          forward("VIEW",param1.type,param1.data);
  223.       }
  224.       
  225.       override public function addModelListener(param1:String, param2:Function) : void
  226.       {
  227.          model.addEventListener(param1.toUpperCase(),param2);
  228.       }
  229.       
  230.       private function setController(param1:ControllerEvent) : void
  231.       {
  232.          forward("CONTROLLER",param1.type,param1.data);
  233.       }
  234.       
  235.       private function addJSControllerListener(param1:String, param2:String) : Boolean
  236.       {
  237.          listeners.push({
  238.             "target":"CONTROLLER",
  239.             "type":param1.toUpperCase(),
  240.             "callee":param2
  241.          });
  242.          return true;
  243.       }
  244.       
  245.       private function setJavascript() : *
  246.       {
  247.          try
  248.          {
  249.             if(ExternalInterface.objectID)
  250.             {
  251.                _config["id"] = ExternalInterface.objectID;
  252.             }
  253.             ExternalInterface.addCallback("getConfig",getConfig);
  254.             ExternalInterface.addCallback("getPlaylist",getPlaylist);
  255.             ExternalInterface.addCallback("addControllerListener",addJSControllerListener);
  256.             ExternalInterface.addCallback("addModelListener",addJSModelListener);
  257.             ExternalInterface.addCallback("addViewListener",addJSViewListener);
  258.             ExternalInterface.addCallback("sendEvent",sendEvent);
  259.             ExternalInterface.addCallback("loadPlugin",loadPlugin);
  260.          }
  261.          catch(err:Error)
  262.          {
  263.          }
  264.       }
  265.       
  266.       private function setModel(param1:ModelEvent) : void
  267.       {
  268.          forward("MODEL",param1.type,param1.data);
  269.       }
  270.       
  271.       override public function addControllerListener(param1:String, param2:Function) : void
  272.       {
  273.          controller.addEventListener(param1.toUpperCase(),param2);
  274.       }
  275.       
  276.       override public function sendEvent(param1:String, param2:Object = undefined) : void
  277.       {
  278.          var _loc3_:Object = null;
  279.          param1 = param1.toUpperCase();
  280.          _loc3_ = new Object();
  281.          switch(param1)
  282.          {
  283.             case "TRACE":
  284.                _loc3_["message"] = param2;
  285.                break;
  286.             case "LINK":
  287.                if(param2 != null)
  288.                {
  289.                   _loc3_["index"] = param2;
  290.                }
  291.                break;
  292.             case "LOAD":
  293.                _loc3_["object"] = param2;
  294.                break;
  295.             case "ITEM":
  296.                if(param2 > -1)
  297.                {
  298.                   _loc3_["index"] = param2;
  299.                }
  300.                break;
  301.             case "SEEK":
  302.                _loc3_["position"] = param2;
  303.                break;
  304.             case "VOLUME":
  305.                _loc3_["percentage"] = param2;
  306.                break;
  307.             default:
  308.                if(param2 != null && param2 != "")
  309.                {
  310.                   if(param2 == true || param2 == "true")
  311.                   {
  312.                      _loc3_["state"] = true;
  313.                   }
  314.                   else if(param2 == false || param2 == "false")
  315.                   {
  316.                      _loc3_["state"] = false;
  317.                   }
  318.                }
  319.          }
  320.          dispatchEvent(new ViewEvent(param1,_loc3_));
  321.       }
  322.       
  323.       private function resizeHandler(param1:Event = undefined) : void
  324.       {
  325.          dispatchEvent(new ViewEvent(ViewEvent.REDRAW));
  326.       }
  327.       
  328.       public function loadPlugin(param1:String, param2:String = null) : Boolean
  329.       {
  330.          var _loc3_:Array = null;
  331.          var _loc4_:* = null;
  332.          var _loc5_:Array = null;
  333.          if(param2 != null && param2 != "")
  334.          {
  335.             _loc3_ = param2.split("&");
  336.             for(_loc4_ in _loc3_)
  337.             {
  338.                _loc5_ = _loc3_[_loc4_].split("=");
  339.                _config[_loc5_[0]] = Strings.serialize(_loc5_[1]);
  340.             }
  341.          }
  342.          loader.loadPlugins(param1);
  343.          return true;
  344.       }
  345.       
  346.       override public function addViewListener(param1:String, param2:Function) : void
  347.       {
  348.          this.addEventListener(param1.toUpperCase(),param2);
  349.       }
  350.       
  351.       override public function get skin() : MovieClip
  352.       {
  353.          return _skin;
  354.       }
  355.    }
  356. }
  357.